/*
Description : This Procedure Gets the Purchase Order Line Item details for Auto Invoicing 
From the Adaptor generated values. 

Tables : Auto_Invoice_PO ( Adaptor Generated Table )     

Author : Sharath

Created On : 6th April 2004

Usage : EXEC sp_ct_load_po_lineitems_for_auto_invoice 'Q54' , 16384, 20
*/


ALTER  PROC sp_ct_load_po_lineitems_for_auto_invoice ( @ponumber CHAR(17), @ord INT, @unit_cost FLOAT )
AS

BEGIN

	DECLARE @results Table ( QTYRECVD BIGINT , EXTDCOST FLOAT )
	DECLARE @quantity_received 		BIGINT	--Represents Qty ShippedPO Line Item Number
	DECLARE @extended_cost       	FLOAT	--Represents Extended Cost
  
	SET @quantity_received = 0
	SET @extended_cost = 0

	SELECT @quantity_received = SUM ( QTYRECVD) FROM AUTO_INVOICE_PO 
	    WHERE POPRCTNM IS NULL AND PONUMBER = @ponumber AND PO_ORD = @ord

	SET @extended_cost = @quantity_received * @unit_cost
	INSERT INTO @results VALUES ( @quantity_received, @extended_cost )
    
  	SELECT * FROM @results 

END